IF EXISTS ( SELECT  *
            FROM    dbo.sysobjects
            WHERE   id = OBJECT_ID(N'[CGO_EventGameAdd]')
                    AND OBJECTPROPERTY(id, N'IsProcedure') = 1 ) 
  DROP PROCEDURE CGO_EventGameAdd
GO

SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.CGO_EventGameAdd
  @PortalID INT,
  @EventID INT ,
  @GameID INT
AS 
  IF EXISTS ( SELECT  1
              FROM    dbo.CGO_Event
              WHERE   EventID = @EventID
                      AND PortalID = @PortalID )
    AND EXISTS ( SELECT 1
                 FROM   dbo.CGO_Game
                 WHERE  GameID = @GameID ) 
    BEGIN
      INSERT INTO dbo.CGO_EventGame
              ( PortalID, EventID, GameID )
      VALUES  ( @PortalID, -- PortalID - int
                @EventID, -- EventID - int
                @GameID  -- GameID - int
                )              
    END
GO
